<?php
/**
 * Created by PhpStorm.
 * User: zjq
 * Date: 2016-06-29
 * Time: 16:26
 */
namespace Mengwu\Controller;
use Admin\Api\DatatreeApi;
use Admin\Api\VPostInfoApi;
use Admin\Api\PostApi;
class HelpCenterController extends BaseStoreController{
    function index(){
        $id = I('get.id',0);
        if($id){
            //AJAX异步请求
            $map = array('id'=>$id);
            $result = apiCall(PostApi::GET_INFO, array($map));
            if(!$result['status']){
                $this->error($result['info']);
            }
            if(is_null($result['info'])){
                $data['title'] = '错误';
                $data['content'] = '该文章不存在！';
                echo(json_encode($data));
            }else{
                $content = htmlspecialchars_decode($result['info']['post_content']);
                $data['title'] = $result['info']['post_title'];
                $data['content'] =  $content;
                echo(json_encode($data));
            }
        }else{
            $this->assignTitle('帮助中心');
            //显示主页
            $result  = apiCall(DatatreeApi::QUERY_NO_PAGING,array(array('parentid'=>C('datatree.HELP_POST_CATEGORY'))));

            if($result['status']){
                $this->assign("article_cates",$result['info']);//帮助中心分类名称列出
            }
            if($result['info']){
                $map = array();
                $map['post_category'] =array('in',implode(',',array_column($result['info'],"id")));
                $result = apiCall(VPostInfoApi::QUERY,array($map));
                $this->assign("article_title",$result['info']['list']);//问题列表
            }

            $this->boye_display();
        }
    }

}
